home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / bench / RCS / server.c,v < prev   
Encoding:
Text File  |  1990-02-16  |  37.7 KB  |  1,643 lines

  1. head     1.12;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.12
  10. date     90.02.16.11.10.41;  author jhh;  state Exp;
  11. branches ;
  12. next     1.11;
  13.  
  14. 1.11
  15. date     89.08.03.16.07.09;  author brent;  state Exp;
  16. branches ;
  17. next     1.10;
  18.  
  19. 1.10
  20. date     89.01.04.15.37.24;  author david;  state Exp;
  21. branches ;
  22. next     1.9;
  23.  
  24. 1.9
  25. date     88.09.29.17.02.51;  author david;  state Exp;
  26. branches ;
  27. next     1.8;
  28.  
  29. 1.8
  30. date     88.09.13.17.30.30;  author brent;  state Exp;
  31. branches ;
  32. next     1.7;
  33.  
  34. 1.7
  35. date     88.08.26.17.48.28;  author brent;  state Exp;
  36. branches ;
  37. next     1.6;
  38.  
  39. 1.6
  40. date     87.12.22.10.15.20;  author brent;  state Exp;
  41. branches ;
  42. next     1.5;
  43.  
  44. 1.5
  45. date     87.07.14.10.26.39;  author brent;  state Exp;
  46. branches ;
  47. next     1.4;
  48.  
  49. 1.4
  50. date     87.05.21.17.50.37;  author andrew;  state Exp;
  51. branches ;
  52. next     1.3;
  53.  
  54. 1.3
  55. date     87.05.21.16.59.44;  author brent;  state Exp;
  56. branches ;
  57. next     1.2;
  58.  
  59. 1.2
  60. date     87.05.01.15.49.52;  author brent;  state Exp;
  61. branches ;
  62. next     1.1;
  63.  
  64. 1.1
  65. date     87.04.01.10.39.58;  author brent;  state Exp;
  66. branches ;
  67. next     ;
  68.  
  69.  
  70. desc
  71. @Code for a server process to use a pseudo device to synchronize N clients.
  72. @
  73.  
  74.  
  75. 1.12
  76. log
  77. @Option to start server on signal
  78. @
  79. text
  80. @/* 
  81.  * server.c --
  82.  *
  83.  *    The server part of some multi-program synchronization primatives.
  84.  *    The routines here control N client programs.  This just means
  85.  *    telling them all to start, and hearing back from them when they're done.
  86.  *
  87.  * Copyright 1986 Regents of the University of California
  88.  * All rights reserved.
  89.  */
  90.  
  91. #ifndef lint
  92. static char rcsid[] = "$Header: /a/newcmds/bench/RCS/server.c,v 1.11 89/08/03 16:07:09 brent Exp $ SPRITE (Berkeley)";
  93. #endif not lint
  94.  
  95.  
  96. #include "sprite.h"
  97. #include "status.h"
  98. #include "fs.h"
  99. #include "dev/pdev.h"
  100. #include "sys/file.h"
  101. #include "stdio.h"
  102. #include "bit.h"
  103. #include "sys.h"
  104.  
  105. char *pdev="/sprite/daemons/bench.pdev";
  106.  
  107. typedef int  (*IntProc)();
  108.  
  109. typedef struct ServerState {
  110.     int cntlStream;        /* StreamID of pdev control stream */
  111.     int numClients;        /* Number of client processes */
  112.     int *clientStream;        /* Array of server streamIDs used to communicate
  113.                  * with the N clients */
  114.     int maxStreamID;        /* Largest value in clientStream array */
  115.     char *clientState;        /* Array of state words, one per client */
  116.     Address *requestBuf;    /* Array of pointers to request buffers.  The
  117.                  * kernel puts request directly into these. */
  118.     int *selectMask;        /* Mask used to wait for requests */
  119.     int selectMaskBytes;    /* Number of bytes in selectMask */
  120.     IntProc opTable[7];        /* Op. switch for servicing requests */
  121. } ServerState;
  122.  
  123. /*
  124.  * Flags for the client state words.
  125.  */
  126. #define CLIENT_OPENED    0x1
  127. #define CLIENT_STARTED    0x2
  128. #define CLIENT_FINISHED    0x4
  129.  
  130. /*
  131.  * The size of the request buffers.
  132.  */
  133. #define REQ_BUF_SIZE    128
  134.  
  135. extern int errno;
  136.  
  137. /*
  138.  * Forward Declarations
  139.  */
  140. ReturnStatus ServeOpen();
  141. ReturnStatus ServeRead();
  142. ReturnStatus ServeWrite();
  143. ReturnStatus ServeIOControl();
  144. ReturnStatus ServeClose();
  145.  
  146. Pdev_Op ServeRequest();
  147.  
  148.  
  149. /*
  150.  *----------------------------------------------------------------------
  151.  *
  152.  * ServerSetup --
  153.  *
  154.  *    Establish contact with N clients.  A pseudo device is opened
  155.  *    and we are declared its "master", or "server".  After this
  156.  *    other processes can open the pseudo device and we'll get a private
  157.  *    stream back that we use for requests from that process.
  158.  *
  159.  * Results:
  160.  *    A pointer to state about the clients needed by ServerStart and
  161.  *    ServerWait.
  162.  *
  163.  * Side effects:
  164.  *    Opens the pseudo device as the server and waits for numClients
  165.  *    opens by client processes.
  166.  *    This exits (kills the process) upon error.
  167.  *
  168.  *----------------------------------------------------------------------
  169.  */
  170.  
  171. void
  172. ServerSetup(numClients, dataPtr)
  173.     int numClients;
  174.     ClientData *dataPtr;
  175. {
  176.     ServerState *statePtr;
  177.     int client;
  178.     int len;
  179.     int amountRead;
  180.     ReturnStatus status;
  181.     Pdev_Notify notify;
  182.     int streamID;
  183.     Pdev_SetBufArgs setBuf;
  184.     extern Boolean waitForSignal;
  185.     extern Boolean startClients;
  186.  
  187.     statePtr = (ServerState *)malloc(sizeof(ServerState));
  188.     statePtr->clientStream = (int *)malloc(numClients * sizeof(int));
  189.     statePtr->clientState = (char *)malloc(numClients);
  190.     statePtr->requestBuf = (Address *)malloc(numClients * sizeof(Address));
  191.     statePtr->numClients = numClients;
  192.  
  193.     statePtr->opTable[(int)PDEV_OPEN] = ServeOpen;
  194.     statePtr->opTable[(int)PDEV_CLOSE] = ServeClose;
  195.     statePtr->opTable[(int)PDEV_READ] = ServeRead;
  196.     statePtr->opTable[(int)PDEV_WRITE] = ServeWrite;
  197.     statePtr->opTable[(int)PDEV_IOCTL] = ServeIOControl;
  198.  
  199.     /*
  200.      * Open the pseudo device.
  201.      */
  202.     statePtr->cntlStream = open(pdev, O_RDONLY|O_MASTER, 0666);
  203.     if (statePtr->cntlStream < 0) {
  204.     statePtr->cntlStream = open(pdev, O_CREAT|O_RDONLY|O_MASTER, 0666);
  205.     }
  206.     if (statePtr->cntlStream < 0) {
  207.     Stat_PrintMsg(errno, "Error opening pseudo device as master");
  208.     exit(errno);
  209.     }
  210.     for (client=0 ; client<numClients ; client++) {
  211.     /*
  212.      * Read on our control stream (the one we just opened) messages
  213.      * that contain new streamIDs.  These are for private streams
  214.      * back to the client process.
  215.      */
  216.     len = sizeof(notify);
  217.     amountRead = read(statePtr->cntlStream, (Address)¬ify, len);
  218.     if (amountRead < 0) {
  219.         Stat_PrintMsg(errno, "Error reading control stream");
  220.         exit(errno);
  221.     } else if (amountRead != sizeof(notify)) {
  222.         fprintf(stderr,
  223.         "Warning, short read (%d) on control stream\n", amountRead);
  224.         fflush(stderr);
  225.     }
  226.     streamID = notify.newStreamID;
  227.     if (streamID > statePtr->maxStreamID) {
  228.         statePtr->maxStreamID = streamID;
  229.     }
  230.     /*
  231.      * Set up state for the client.
  232.      */
  233.     statePtr->clientStream[client] = streamID;
  234.     statePtr->clientState[client] = CLIENT_OPENED;
  235.     statePtr->requestBuf[client] = (Address) malloc(REQ_BUF_SIZE);
  236.     /*
  237.      * Tell the kernel where the request buffer is.
  238.      */
  239.     setBuf.requestBufAddr = statePtr->requestBuf[client];
  240.     setBuf.requestBufSize = REQ_BUF_SIZE;
  241.     setBuf.readBufAddr = NULL;
  242.     setBuf.readBufSize = 0;
  243.     Fs_IOControl(streamID, IOC_PDEV_SET_BUF, sizeof(Pdev_SetBufArgs),
  244.             (Address)&setBuf, 0, (Address)NULL);
  245.  
  246.     fprintf(stderr, "Got client on stream %d\n",streamID);
  247.     fflush(stderr);
  248.     }
  249.     if (waitForSignal) {
  250.     while (!startClients) {
  251.         sigpause(0);
  252.     }
  253.     }
  254.     /*
  255.      * Now start all clients at once by servicing their first PDEV_OPEN
  256.      * request.
  257.      */
  258.     for (client=0 ; client<numClients ; client++) {
  259.     (void) ServeRequest(statePtr->clientStream[client],
  260.              statePtr->requestBuf[client], statePtr->opTable);
  261.     }
  262.     fflush(stderr);
  263.     /*
  264.      * Now that we know the largest stream ID used for a client stream
  265.      * we can allocate and initialize the select mask for the streams.
  266.      */
  267.     statePtr->selectMaskBytes = Bit_NumBytes(statePtr->maxStreamID);
  268.     statePtr->selectMask = (int *)malloc(statePtr->selectMaskBytes);
  269.     bzero((Address)statePtr->selectMask, statePtr->selectMaskBytes);
  270.     for (client=0 ; client < numClients ; client++) {
  271.     Bit_Set(statePtr->clientStream[client], statePtr->selectMask);
  272.     }
  273.     *dataPtr = (ClientData)statePtr;
  274. }
  275.  
  276. /*
  277.  *----------------------------------------------------------------------
  278.  *
  279.  * ServeRequest --
  280.  *
  281.  *    The top level service routine that reads client requests
  282.  *    and branches out to a handler for the request.  This takes
  283.  *    care of error conditions and allocating space for the
  284.  *    request and the reply parameters.
  285.  *
  286.  * Results:
  287.  *    None
  288.  *
  289.  * Side effects:
  290.  *    Reads and writes on the client's stream.  malloc space for the
  291.  *    request and the reply.  Will reset the client stream upon error.
  292.  *
  293.  *----------------------------------------------------------------------
  294.  */
  295.  
  296. Pdev_Op
  297. ServeRequest(clientStreamID, requestBuf, opTable)
  298.     int clientStreamID;        /* StreamID of private channel to client */
  299.     Address requestBuf;        /* Buffer that holds client's requests */
  300.     IntProc *opTable;        /* Operation switch table */
  301. {
  302.     int amountRead;
  303.     ReturnStatus status;
  304.     Pdev_BufPtrs bufPtrs;        /* Used to read ptrs into req. buf. */
  305.     Pdev_Request *requestPtr;    /* Points to request header */
  306.     Pdev_Reply reply;
  307.     Address requestData;        /* Points to data that follows header */
  308.     char replyBuf[1024];
  309.     char *replyData = replyBuf;        /* Points to reply data */
  310.     int replySize;            /* Amount of valid data in replyBuf */
  311.     Boolean alloc;
  312.  
  313.     /*
  314.      * Read the request header that indicates the operation and the
  315.      * offset within the request buffer of the request message.
  316.      */
  317.     amountRead = read(clientStreamID, (Address)&bufPtrs, sizeof(Pdev_BufPtrs));
  318.     if (amountRead < 0) { 
  319.     Stat_PrintMsg(errno, "ServeRequest: error reading request bufPtrs");
  320.     goto failure;
  321.     } else if (amountRead != sizeof(Pdev_BufPtrs)) {
  322.     fprintf(stderr,
  323.         "ServeRequest: short read (%d) of request bufPtrs\n", amountRead);
  324.     fflush(stderr);
  325.     goto failure;
  326.     } else if ((int)bufPtrs.magic != PDEV_BUF_PTR_MAGIC) {
  327.     fprintf(stderr, "ServeRequest: bad bufPtr magic 0x%x\n",
  328.         bufPtrs.magic);
  329.     status = FAILURE;
  330.     goto failure;
  331.     }
  332.     /*
  333.      * While there are still requests in the buffer, service them.
  334.      */
  335.     while (bufPtrs.requestFirstByte < bufPtrs.requestLastByte) {
  336.     requestPtr = (Pdev_Request *)&requestBuf[bufPtrs.requestFirstByte];
  337.     if (requestPtr->hdr.magic != PDEV_REQUEST_MAGIC) {
  338.         /*
  339.         Sys_Panic(SYS_FATAL, "ServeRequest, bad request magic # 0x%x\n",
  340.                 requestPtr->magic);
  341.         */
  342.         abort();
  343.     }
  344.     /*
  345.      * Set up a buffer for the reply data;
  346.      */
  347.     if (requestPtr->hdr.replySize > 1024) {
  348.         alloc = TRUE;
  349.         replyData = (Address) malloc(requestPtr->hdr.replySize);
  350.     } else {
  351.         alloc = FALSE;
  352.         replyData = replyBuf;
  353.     }
  354.     requestData = (Address)((int)requestPtr + sizeof(Pdev_Request));
  355.     /*
  356.      * Switch out the to the handler for the pdev operation.
  357.      */
  358.     status = (*opTable[(int)requestPtr->hdr.operation])(clientStreamID,
  359.             requestPtr, requestData, replyData, &replySize);
  360.     /*
  361.      * Copy the data into the reply and give it to the kernel.
  362.      */
  363.     
  364.     reply.magic = PDEV_REPLY_MAGIC;
  365.     reply.status = status;
  366.     reply.selectBits = FS_READ|FS_WRITE;
  367.     reply.replySize = replySize;
  368.     reply.replyBuf = replyData;
  369.     reply.signal = 0;
  370.     reply.code = 0;
  371.     status = Fs_IOControl(clientStreamID, IOC_PDEV_REPLY,
  372.                 sizeof(Pdev_Reply), (Address) &reply, 0,
  373.                 (Address) NULL);
  374.     if (status != SUCCESS) {
  375.         /*
  376.         Sys_Panic(SYS_FATAL, "%s; status \"%s\"",
  377.             "ServeRequest couldn't send reply",
  378.             Stat_GetMsg(status));
  379.         */
  380.         abort();
  381.     }
  382.     if (alloc) {
  383.         free(replyData);
  384.     }
  385.     /*
  386.      * Tell the kernel we removed a request and see if there are any more.
  387.      */
  388.     bufPtrs.requestFirstByte += requestPtr->hdr.messageSize;
  389.     Fs_IOControl(clientStreamID, IOC_PDEV_SET_PTRS,
  390.             sizeof(Pdev_BufPtrs), (Address)&bufPtrs, 0, (Address) NULL);
  391.     }
  392.     return(requestPtr->hdr.operation);
  393.  
  394. failure:
  395.     /*
  396.      * Couldn't even get started right.  We'd like to be able to "reset
  397.      * the connection" at this point - do something to cause the waiting
  398.      * client to return, and something to flush any remaining input
  399.      * in the request stream.  Need a special IOControl.
  400.      */
  401.     close(clientStreamID);
  402.     return((Pdev_Op)-1);
  403. }
  404.  
  405. /*
  406.  *----------------------------------------------------------------------
  407.  *
  408.  * Serve --
  409.  *
  410.  *    Listen for requests from client's, returning after all clients
  411.  *    have closed their streams.
  412.  *
  413.  * Results:
  414.  *    None
  415.  *
  416.  * Side effects:
  417.  *    Handle all requests by clients.
  418.  *
  419.  *----------------------------------------------------------------------
  420.  */
  421.  
  422. void
  423. Serve(data)
  424.     ClientData data;
  425. {
  426.     ServerState *statePtr;
  427.     int client;
  428.     ReturnStatus status;
  429.     int *selectMask;
  430.     int numFinishedClients;
  431.     int numReady;
  432.     int numBits;
  433.  
  434.     statePtr = (ServerState *)data;
  435.     selectMask = (int *)malloc(statePtr->selectMaskBytes);
  436.     numBits = statePtr->selectMaskBytes * BIT_NUM_BITS_PER_BYTE;
  437.     numFinishedClients = 0;
  438.     do {
  439.     bcopy( (Address)statePtr->selectMask, (Address)selectMask, 
  440.         statePtr->selectMaskBytes);
  441.     status = Fs_Select(numBits, (Time *)NULL, selectMask,
  442.                 (int *)NULL, (int *)NULL, &numReady);
  443.     if (status != SUCCESS) {
  444.         /*
  445.         Sys_Panic(SYS_FATAL, "Serve: select failed, %s\n",
  446.         Stat_GetMsg(status));
  447.        */
  448.        abort();
  449.     }
  450.     for (client=0 ; client < statePtr->numClients ; client++) {
  451.         /*
  452.          * Look for the each client's bit in the select mask and
  453.          * service requests that have arrived.
  454.          */
  455.         if (Bit_IsSet(statePtr->clientStream[client], selectMask)) {
  456.         /*
  457.          * Handle the client's request.  If it's a close
  458.          * then clear the client's bit from the select mask so
  459.          * don't bother checking it again.
  460.          */
  461.         if (ServeRequest(statePtr->clientStream[client],
  462.                  statePtr->requestBuf[client],
  463.                  statePtr->opTable) == PDEV_CLOSE) {
  464.             fprintf(stderr, "Client %d closed... ", client);
  465.             fflush(stderr);
  466.             numFinishedClients++;
  467.             statePtr->clientState[client] |= CLIENT_FINISHED;
  468.             Bit_Clear(statePtr->clientStream[client],
  469.                 statePtr->selectMask);
  470.         }
  471.         }
  472.     }
  473.     } while (numFinishedClients < statePtr->numClients);
  474.     fprintf(stderr, "\n");
  475.     fflush(stderr);
  476. }
  477.  
  478. /*
  479.  *----------------------------------------------------------------------
  480.  *
  481.  * ServeOpen --
  482.  *
  483.  *    React to an Open or Dup request.
  484.  *
  485.  * Results:
  486.  *    SUCCESS
  487.  *
  488.  * Side effects:
  489.  *    Print statement.
  490.  *
  491.  *----------------------------------------------------------------------
  492.  */
  493. /*ARGSUSED*/
  494. ReturnStatus
  495. ServeOpen(streamID, requestPtr, requestData, replyData, replySizePtr)
  496.     int streamID;
  497.     Pdev_Request *requestPtr;
  498.     Address requestData;
  499.     Address replyData;
  500.     int *replySizePtr;
  501. {
  502.     fprintf(stderr, "Open request, streamID %d, pid %x\n",
  503.         streamID, requestPtr->param.open.pid);
  504.     fflush(stderr);
  505.     *replySizePtr = 0;
  506.     return(SUCCESS);
  507. }
  508.  
  509. /*
  510.  *----------------------------------------------------------------------
  511.  *
  512.  * ServeRead --
  513.  *
  514.  *    Return data for a read request.
  515.  *
  516.  * Results:
  517.  *    SUCCESS
  518.  *
  519.  * Side effects:
  520.  *    Zeroes out the reply buffer.
  521.  *
  522.  *----------------------------------------------------------------------
  523.  */
  524. /*ARGSUSED*/
  525. ReturnStatus
  526. ServeRead(streamID, requestPtr, requestBuf, replyBuf, replySizePtr)
  527.     int streamID;
  528.     Pdev_Request *requestPtr;
  529.     Address requestBuf;
  530.     Address replyBuf;
  531.     int *replySizePtr;
  532. {
  533.     if (requestPtr->hdr.replySize > 0) {
  534.     bzero(replyBuf, requestPtr->hdr.replySize);
  535.     }
  536.     *replySizePtr = requestPtr->hdr.replySize;
  537.     return(SUCCESS);
  538. }
  539.  
  540. /*
  541.  *----------------------------------------------------------------------
  542.  *
  543.  * ServeWrite --
  544.  *
  545.  *    Handle a write request.
  546.  *
  547.  * Results:
  548.  *    SUCCESS
  549.  *
  550.  * Side effects:
  551.  *    Sets up the return value, the number of bytes written.
  552.  *
  553.  *----------------------------------------------------------------------
  554.  */
  555. /*ARGSUSED*/
  556. ReturnStatus
  557. ServeWrite(streamID, requestPtr, requestBuf, replyBuf, replySizePtr)
  558.     int streamID;
  559.     Pdev_Request *requestPtr;
  560.     Address requestBuf;
  561.     Address replyBuf;
  562.     int *replySizePtr;
  563. {
  564.     *replySizePtr = 0;
  565.     return(SUCCESS);
  566. }
  567.  
  568. /*
  569.  *----------------------------------------------------------------------
  570.  *
  571.  * ServeIOControl --
  572.  *
  573.  *    Handle an IOControl.  This acts like an echo now.
  574.  *
  575.  * Results:
  576.  *    SUCCESS
  577.  *
  578.  * Side effects:
  579.  *    Copies the request buffer to the reply buffer.
  580.  *
  581.  *----------------------------------------------------------------------
  582.  */
  583. /*ARGSUSED*/
  584. ReturnStatus
  585. ServeIOControl(streamID, requestPtr, requestBuf, replyBuf, replySizePtr)
  586.     int streamID;
  587.     Pdev_Request *requestPtr;
  588.     Address requestBuf;
  589.     Address replyBuf;
  590.     int *replySizePtr;
  591. {
  592.     if (requestPtr->hdr.replySize <= requestPtr->hdr.requestSize) {
  593.     bcopy(requestBuf, replyBuf, requestPtr->hdr.replySize);
  594.     } else {
  595.     bcopy(requestBuf, replyBuf, requestPtr->hdr.requestSize);
  596.     bzero( replyBuf[requestPtr->hdr.requestSize],
  597.         requestPtr->hdr.replySize - requestPtr->hdr.requestSize);
  598.     }
  599.     *replySizePtr = requestPtr->hdr.replySize;
  600.     return(SUCCESS);
  601. }
  602.  
  603. /*
  604.  *----------------------------------------------------------------------
  605.  *
  606.  * ServeClose --
  607.  *
  608.  *    Handle a close request.
  609.  *
  610.  * Results:
  611.  *    SUCCESS
  612.  *
  613.  * Side effects:
  614.  *    None.
  615.  *
  616.  *----------------------------------------------------------------------
  617.  */
  618. /*ARGSUSED*/
  619. ReturnStatus
  620. ServeClose(streamID, requestPtr, requestBuf, replyBuf, replySizePtr)
  621.     int streamID;
  622.     Pdev_Request *requestPtr;
  623.     Address requestBuf;
  624.     Address replyBuf;
  625.     int *replySizePtr;
  626. {
  627.     *replySizePtr = 0;
  628.     return(SUCCESS);
  629. }
  630. @
  631.  
  632.  
  633. 1.11
  634. log
  635. @Updated to new Pdev_Reply struct
  636. @
  637. text
  638. @d13 1
  639. a13 1
  640. static char rcsid[] = "$Header: /a/newcmds/devbench/RCS/server.c,v 1.10 89/01/04 15:37:24 david Exp $ SPRITE (Berkeley)";
  641. d105 2
  642. d169 5
  643. @
  644.  
  645.  
  646. 1.10
  647. log
  648. @Convert to machine dependent format and prints SPUR cache controller
  649. register results.
  650. @
  651. text
  652. @d13 1
  653. a13 1
  654. static char rcsid[] = "$Header: server.c,v 1.9 88/09/29 17:02:51 david Exp $ SPRITE (Berkeley)";
  655. d26 1
  656. a26 1
  657. char *pdev="/sprite/daemons/devbench";
  658. d283 2
  659. @
  660.  
  661.  
  662. 1.9
  663. log
  664. @
  665. @
  666. text
  667. @d13 1
  668. a13 1
  669. static char rcsid[] = "$Header: server.c,v 1.8 88/09/13 17:30:30 brent Exp $ SPRITE (Berkeley)";
  670. d251 1
  671. a251 1
  672.     if (requestPtr->magic != PDEV_REQUEST_MAGIC) {
  673. d261 1
  674. a261 1
  675.     if (requestPtr->replySize > 1024) {
  676. d263 1
  677. a263 1
  678.         replyData = (Address) malloc(requestPtr->replySize);
  679. d272 1
  680. a272 1
  681.     status = (*opTable[(int)requestPtr->operation])(clientStreamID,
  682. d300 1
  683. a300 1
  684.     bufPtrs.requestFirstByte += requestPtr->messageSize;
  685. d304 1
  686. a304 1
  687.     return(requestPtr->operation);
  688. d445 2
  689. a446 2
  690.     if (requestPtr->replySize > 0) {
  691.     bzero(replyBuf, requestPtr->replySize);
  692. d448 1
  693. a448 1
  694.     *replySizePtr = requestPtr->replySize;
  695. d504 2
  696. a505 2
  697.     if (requestPtr->replySize <= requestPtr->requestSize) {
  698.     bcopy(requestBuf, replyBuf, requestPtr->replySize);
  699. d507 3
  700. a509 3
  701.     bcopy(requestBuf, replyBuf, requestPtr->requestSize);
  702.     bzero( replyBuf[requestPtr->requestSize],
  703.         requestPtr->replySize - requestPtr->requestSize);
  704. d511 1
  705. a511 1
  706.     *replySizePtr = requestPtr->replySize;
  707. @
  708.  
  709.  
  710. 1.8
  711. log
  712. @Fixed ancient bug in first argument to Fs_Select,
  713. needs to be number of bits, not number of streams.
  714. @
  715. text
  716. @d13 1
  717. a13 1
  718. static char rcsid[] = "$Header: server.c,v 1.7 88/08/26 17:48:28 brent Exp $ SPRITE (Berkeley)";
  719. d21 2
  720. a22 1
  721. #include "io.h"
  722. a23 1
  723. #include "mem.h"
  724. d26 1
  725. a26 1
  726. char *pdev="/sprite/daemons/devBench";
  727. d56 2
  728. d106 4
  729. a109 4
  730.     statePtr = (ServerState *)Mem_Alloc(sizeof(ServerState));
  731.     statePtr->clientStream = (int *)Mem_Alloc(numClients * sizeof(int));
  732.     statePtr->clientState = (char *)Mem_Alloc(numClients);
  733.     statePtr->requestBuf = (Address *)Mem_Alloc(numClients * sizeof(Address));
  734. d121 3
  735. a123 5
  736.     status = Fs_Open(pdev, FS_READ|FS_NEW_MASTER,
  737.              0666, &statePtr->cntlStream);
  738.     if (status == FS_FILE_NOT_FOUND) {
  739.     status = Fs_Open(pdev, FS_CREATE|FS_READ|FS_NEW_MASTER,
  740.              0666, &statePtr->cntlStream);
  741. d125 3
  742. a127 3
  743.     if (status != SUCCESS) {
  744.     Stat_PrintMsg(status, "Error opening pseudo device as master");
  745.     Proc_Exit(status);
  746. d136 4
  747. a139 5
  748.     status = Fs_Read(statePtr->cntlStream, len, (Address)¬ify,
  749.                          &amountRead);
  750.     if (status != SUCCESS) {
  751.         Stat_PrintMsg(status, "Error reading control stream");
  752.         Proc_Exit(status);
  753. d141 1
  754. a141 1
  755.         Io_PrintStream(io_StdErr,
  756. d143 1
  757. a143 1
  758.         Io_Flush(io_StdErr);
  759. d154 1
  760. a154 1
  761.     statePtr->requestBuf[client] = Mem_Alloc(REQ_BUF_SIZE);
  762. d165 2
  763. a166 2
  764.     Io_PrintStream(io_StdErr, "Got client on stream %d\n",streamID);
  765.     Io_Flush(io_StdErr);
  766. d176 1
  767. a176 1
  768.     Io_Flush(io_StdErr);
  769. d182 2
  770. a183 2
  771.     statePtr->selectMask = (int *)Mem_Alloc(statePtr->selectMaskBytes);
  772.     Byte_Zero(statePtr->selectMaskBytes, (Address)statePtr->selectMask);
  773. d204 1
  774. a204 1
  775.  *    Reads and writes on the client's stream.  Mem_Allocs space for the
  776. d231 3
  777. a233 4
  778.     status = Fs_Read(clientStreamID, sizeof(Pdev_BufPtrs), (Address)&bufPtrs,
  779.         &amountRead);
  780.     if (status != SUCCESS) { 
  781.     Stat_PrintMsg(status, "ServeRequest: error reading request bufPtrs");
  782. d236 1
  783. a236 1
  784.     Io_PrintStream(io_StdErr,
  785. d238 1
  786. a238 1
  787.     Io_Flush(io_StdErr);
  788. d241 1
  789. a241 1
  790.     Io_PrintStream(io_StdErr, "ServeRequest: bad bufPtr magic 0x%x\n",
  791. d252 1
  792. d255 2
  793. d263 1
  794. a263 1
  795.         replyData = Mem_Alloc(requestPtr->replySize);
  796. d287 1
  797. d291 2
  798. d295 1
  799. a295 1
  800.         Mem_Free(replyData);
  801. d313 1
  802. a313 1
  803.     Fs_Close(clientStreamID);
  804. d347 1
  805. a347 1
  806.     selectMask = (int *)Mem_Alloc(statePtr->selectMaskBytes);
  807. d351 2
  808. a352 2
  809.     Byte_Copy(statePtr->selectMaskBytes, (Address)statePtr->selectMask,
  810.                          (Address)selectMask);
  811. d356 1
  812. d359 2
  813. d376 2
  814. a377 2
  815.             Io_PrintStream(io_StdErr, "Client %d closed... ", client);
  816.             Io_Flush(io_StdErr);
  817. d386 2
  818. a387 2
  819.     Io_PrintStream(io_StdErr, "\n");
  820.     Io_Flush(io_StdErr);
  821. d414 1
  822. a414 1
  823.     Io_PrintStream(io_StdErr, "Open request, streamID %d, pid %x\n",
  824. d416 1
  825. a416 1
  826.     Io_Flush(io_StdErr);
  827. d446 1
  828. a446 1
  829.     Byte_Zero(requestPtr->replySize, replyBuf);
  830. d505 1
  831. a505 1
  832.     Byte_Copy(requestPtr->replySize, requestBuf, replyBuf);
  833. d507 3
  834. a509 3
  835.     Byte_Copy(requestPtr->requestSize, requestBuf, replyBuf);
  836.     Byte_Zero(requestPtr->replySize - requestPtr->requestSize,
  837.         replyBuf[requestPtr->requestSize]);
  838. @
  839.  
  840.  
  841. 1.7
  842. log
  843. @UPdated to new, standard, pseudo-device interface
  844. @
  845. text
  846. @d13 1
  847. a13 1
  848. static char rcsid[] = "$Header: server.c,v 1.6 87/12/22 10:15:20 brent Exp $ SPRITE (Berkeley)";
  849. d340 1
  850. d344 1
  851. d349 1
  852. a349 1
  853.     status = Fs_Select(statePtr->numClients, (Time *)NULL, selectMask,
  854. @
  855.  
  856.  
  857. 1.6
  858. log
  859. @Changed to new pseudo-device format
  860. @
  861. text
  862. @d13 1
  863. a13 1
  864. static char rcsid[] = "$Header: server.c,v 1.5 87/07/14 10:26:39 brent Exp $ SPRITE (Berkeley)";
  865. d220 2
  866. a221 2
  867.     Pdev_NewRequest *requestPtr;    /* Points to request header */
  868.     Pdev_NewReply reply;
  869. d252 1
  870. a252 1
  871.     requestPtr = (Pdev_NewRequest *)&requestBuf[bufPtrs.requestFirstByte];
  872. d267 1
  873. a267 1
  874.     requestData = (Address)((int)requestPtr + sizeof(Pdev_NewRequest));
  875. d283 1
  876. a283 1
  877.                 sizeof(Pdev_NewReply), (Address) &reply, 0,
  878. d400 1
  879. a400 1
  880.     Pdev_NewRequest *requestPtr;
  881. d431 1
  882. a431 1
  883.     Pdev_NewRequest *requestPtr;
  884. d462 1
  885. a462 1
  886.     Pdev_NewRequest *requestPtr;
  887. d490 1
  888. a490 1
  889.     Pdev_NewRequest *requestPtr;
  890. d525 1
  891. a525 1
  892.     Pdev_NewRequest *requestPtr;
  893. @
  894.  
  895.  
  896. 1.5
  897. log
  898. @Updated to handle new pseudo-device interface
  899. @
  900. text
  901. @d13 1
  902. a13 1
  903. static char rcsid[] = "$Header: server.c,v 1.4 87/05/21 17:50:37 andrew Exp $ SPRITE (Berkeley)";
  904. d23 2
  905. a27 3
  906. char requestBuffer[4096];
  907. int requestBufSize = sizeof(requestBuffer);
  908.  
  909. d31 11
  910. a41 8
  911.     int cntlStream;
  912.     int numClients;
  913.     int *clientStream;
  914.     int maxStreamID;
  915.     char *clientState;
  916.     int *selectMask;
  917.     int selectMaskBytes;
  918.     IntProc opTable[9];
  919. d44 3
  920. d51 4
  921. a58 1
  922. ReturnStatus NullProc();
  923. a59 1
  924. ReturnStatus ServeDup();
  925. d63 2
  926. a64 1
  927. ReturnStatus ServeSelect();
  928. d102 1
  929. a102 1
  930.     int maxStreamID;
  931. d107 1
  932. d111 1
  933. a111 2
  934.     statePtr->opTable[(int)PDEV_DUP] = ServeDup;
  935.     statePtr->opTable[(int)PDEV_CLOSE] = NullProc;
  936. a114 1
  937.     statePtr->opTable[(int)PDEV_SELECT] = ServeSelect;
  938. d119 1
  939. a119 1
  940.     status = Fs_Open(pdev, FS_READ|FS_MASTER,
  941. d122 1
  942. a122 1
  943.     status = Fs_Open(pdev, FS_CREATE|FS_READ|FS_MASTER,
  944. a128 1
  945.     maxStreamID = 0;
  946. d133 1
  947. a133 1
  948.      * back to the client process..
  949. d150 3
  950. d155 11
  951. d174 2
  952. a175 1
  953.     ServeRequest(statePtr->clientStream[client], statePtr->opTable);
  954. d212 4
  955. a215 3
  956. ServeRequest(clientStreamID, opTable)
  957.     int clientStreamID;
  958.     IntProc *opTable;
  959. a216 2
  960.     ServerState *statePtr;
  961.     int client;
  962. a217 1
  963.     int amountWritten;
  964. d219 8
  965. a226 5
  966.     Pdev_Request request;
  967.     Pdev_Reply reply;
  968.     Address requestBuf;
  969.     Address replyBuf;
  970.     int len;
  971. d230 1
  972. a230 1
  973.      * size of the following request parameters.
  974. d232 2
  975. a233 2
  976.     len = sizeof(request);
  977.     status = Fs_Read(clientStreamID, len, (Address)&request, &amountRead);
  978. d235 1
  979. a235 1
  980.     Stat_PrintMsg(status, "ServeRequest: error reading request header");
  981. d237 1
  982. a237 1
  983.     } else if (amountRead != sizeof(request)) {
  984. d239 1
  985. a239 1
  986.         "ServeRequest: short read (%d) of the request\n", amountRead);
  987. d242 14
  988. a255 6
  989.     } else {
  990.     if ((int)request.magic != PDEV_REQUEST_MAGIC) {
  991.         Io_PrintStream(io_StdErr, "ServeRequest: bad request header 0x%x\n",
  992.             request.magic);
  993.         status = FAILURE;
  994.         goto failure;
  995. d257 6
  996. a262 14
  997.     if (request.requestSize > 0) {
  998.         /*
  999.          * Read the input parameters that follow the request header,
  1000.          * and allocate space for the return parameters.
  1001.          */
  1002.         requestBuf = (Address) Mem_Alloc(request.requestSize);
  1003.         status = Fs_Read(clientStreamID, request.requestSize, requestBuf,
  1004.             &amountRead);
  1005.         if (status != SUCCESS) {
  1006.         Stat_PrintMsg(status,
  1007.                 "ServeRequest: error reading request params");
  1008.         Mem_Free(requestBuf);
  1009.         goto failure;
  1010.         }
  1011. d264 2
  1012. a265 7
  1013.        requestBuf = NULL;
  1014.         }
  1015.  
  1016.     if (request.replySize > 0) {
  1017.         replyBuf = (Address) Mem_Alloc(request.replySize);
  1018.     } else {
  1019.         replyBuf = NULL;
  1020. d267 1
  1021. a267 1
  1022.  
  1023. d271 2
  1024. a272 2
  1025.     status = (*opTable[(int)request.operation])(clientStreamID,
  1026.             &request, requestBuf, replyBuf);
  1027. d274 1
  1028. a274 1
  1029.      * Write the reply header followed by the reply data.
  1030. d276 2
  1031. d279 6
  1032. a284 4
  1033.     reply.replySize = request.replySize;
  1034.     reply.magic = PDEV_REPLY_MAGIC;
  1035.     status = Fs_Write(clientStreamID, sizeof(reply), (Address)&reply,
  1036.             &amountWritten);
  1037. d286 3
  1038. a288 1
  1039.         Stat_PrintMsg(status, "ServeRequest: write of reply header failed");
  1040. d290 2
  1041. a291 8
  1042.     if (replyBuf != NULL) {
  1043.         status = Fs_Write(clientStreamID, reply.replySize, replyBuf,
  1044.             &amountWritten);
  1045.         if (status != SUCCESS) {
  1046.         Stat_PrintMsg(status,
  1047.                   "ServeRequest: write of reply data failed");
  1048.         }
  1049.         Mem_Free(replyBuf);
  1050. d293 6
  1051. a298 4
  1052.     if (requestBuf != NULL) {
  1053.         Mem_Free(requestBuf);
  1054.     }
  1055.     return(request.operation);
  1056. d300 2
  1057. d309 1
  1058. a309 4
  1059.     reply.status = FAILURE;
  1060.     reply.replySize = 0;
  1061.     (void)Fs_Write(clientStreamID, sizeof(reply), (Address)&reply,
  1062.         &amountWritten);
  1063. d347 6
  1064. a352 2
  1065.     status = Fs_Select(statePtr->numClients, NULL, selectMask,
  1066.                 NULL, NULL, &numReady);
  1067. d355 2
  1068. a356 2
  1069.          * Look for the each client's bit in the select mask and read the
  1070.          * corresponding stream for its initial request.
  1071. d365 3
  1072. a367 2
  1073.                  statePtr->opTable) == PDEV_CLOSE) {
  1074.             Io_PrintStream(io_StdErr, "Client %d closed...", client);
  1075. d384 1
  1076. a384 1
  1077.  * NullProc --
  1078. d386 1
  1079. a386 1
  1080.  *    The do-nothing service procedure.
  1081. d392 1
  1082. a392 1
  1083.  *    Zeroes out the reply buffer.
  1084. d396 1
  1085. a396 1
  1086.  
  1087. d398 1
  1088. a398 1
  1089. NullProc(streamID, requestPtr, requestBuf, replyBuf)
  1090. d400 4
  1091. a403 3
  1092.     Pdev_Request *requestPtr;
  1093.     Address requestBuf;
  1094.     Address replyBuf;
  1095. d405 4
  1096. a408 3
  1097.     if (requestPtr->replySize > 0) {
  1098.     Byte_Zero(requestPtr->replySize, replyBuf);
  1099.     }
  1100. d427 1
  1101. d429 1
  1102. a429 1
  1103. ServeRead(streamID, requestPtr, requestBuf, replyBuf)
  1104. d431 1
  1105. a431 1
  1106.     Pdev_Request *requestPtr;
  1107. d434 1
  1108. d439 1
  1109. a445 62
  1110.  * ServeOpen --
  1111.  *
  1112.  *    React to an Open or Dup request.
  1113.  *
  1114.  * Results:
  1115.  *    SUCCESS
  1116.  *
  1117.  * Side effects:
  1118.  *    Print statement.
  1119.  *
  1120.  *----------------------------------------------------------------------
  1121.  */
  1122. ReturnStatus
  1123. ServeOpen(streamID, requestPtr, requestBuf, replyBuf)
  1124.     int streamID;
  1125.     Pdev_Request *requestPtr;
  1126.     Address requestBuf;
  1127.     Address replyBuf;
  1128. {
  1129.     Pdev_OpenParam *paramPtr;
  1130.  
  1131.     paramPtr = (Pdev_OpenParam *)requestBuf;
  1132.     Io_PrintStream(io_StdErr, "Open request, streamID %d, clientID %d\n",
  1133.         streamID, requestPtr->param.open.clientID);
  1134.     Io_Flush(io_StdErr);
  1135.     return(SUCCESS);
  1136. }
  1137.  
  1138. /*
  1139.  *----------------------------------------------------------------------
  1140.  *
  1141.  * ServeDup --
  1142.  *
  1143.  *    React to a Dup request.
  1144.  *
  1145.  * Results:
  1146.  *    SUCCESS
  1147.  *
  1148.  * Side effects:
  1149.  *    Print statement.
  1150.  *
  1151.  *----------------------------------------------------------------------
  1152.  */
  1153. ReturnStatus
  1154. ServeDup(streamID, requestPtr, requestBuf, replyBuf)
  1155.     int streamID;
  1156.     Pdev_Request *requestPtr;
  1157.     Address requestBuf;
  1158.     Address replyBuf;
  1159. {
  1160.     Pdev_OpenParam *paramPtr;
  1161.  
  1162.     paramPtr = (Pdev_OpenParam *)requestBuf;
  1163.     Io_PrintStream(io_StdErr, "Dup request, streamID %d, clientID %d\n",
  1164.         streamID, requestPtr->param.open.clientID);
  1165.     Io_Flush(io_StdErr);
  1166.     return(SUCCESS);
  1167. }
  1168.  
  1169. /*
  1170.  *----------------------------------------------------------------------
  1171.  *
  1172. d458 1
  1173. d460 1
  1174. a460 1
  1175. ServeWrite(streamID, requestPtr, requestBuf, replyBuf)
  1176. d462 1
  1177. a462 1
  1178.     Pdev_Request *requestPtr;
  1179. d465 1
  1180. d467 1
  1181. a467 4
  1182.     int *intPtr;
  1183.  
  1184.     intPtr = (int *)replyBuf;
  1185.     *intPtr = requestPtr->requestSize;
  1186. d486 1
  1187. d488 1
  1188. a488 1
  1189. ServeIOControl(streamID, requestPtr, requestBuf, replyBuf)
  1190. d490 1
  1191. a490 1
  1192.     Pdev_Request *requestPtr;
  1193. d493 1
  1194. d502 1
  1195. d509 1
  1196. a509 1
  1197.  * ServeSelect --
  1198. d511 1
  1199. a511 1
  1200.  *    Handle a select.  This pseudo-device is always ready.
  1201. d521 1
  1202. d523 1
  1203. a523 1
  1204. ServeSelect(streamID, requestPtr, requestBuf, replyBuf)
  1205. d525 1
  1206. a525 1
  1207.     Pdev_Request *requestPtr;
  1208. d528 1
  1209. d530 1
  1210. a530 4
  1211.     int *intPtr;
  1212.  
  1213.     intPtr = (int *)replyBuf;
  1214.     *intPtr = FS_READABLE|FS_WRITABLE;
  1215. @
  1216.  
  1217.  
  1218. 1.4
  1219. log
  1220. @updated to corrspond to new pdev protocol in fsPdev.c
  1221. @
  1222. text
  1223. @d13 1
  1224. a13 1
  1225. static char rcsid[] = "$Header: server.c,v 1.3 87/05/21 16:59:44 brent Exp $ SPRITE (Berkeley)";
  1226. d20 1
  1227. a20 1
  1228. #include "kernel/fsPdev.h"
  1229. d24 1
  1230. a24 1
  1231. char *devBench="/sprite/daemons/devBench";
  1232. d29 1
  1233. a29 10
  1234. typedef struct Fs_PdevOpTable {
  1235.     ReturnStatus (*open)();
  1236.     ReturnStatus (*close)();
  1237.     ReturnStatus (*read)();
  1238.     ReturnStatus (*write)();
  1239.     ReturnStatus (*ioctl)();
  1240.     ReturnStatus (*getAttr)();
  1241.     ReturnStatus (*setAttr)();
  1242.     ReturnStatus (*select)();
  1243. } Fs_PdevOpTable;
  1244. d32 1
  1245. a32 1
  1246.     int devBenchStream;
  1247. d39 1
  1248. a39 1
  1249.     Fs_PdevOpTable opTable;
  1250. d51 7
  1251. a57 1
  1252. void ServeRequest();
  1253. d92 2
  1254. a93 1
  1255.     Fs_PdevRequest notify;
  1256. d101 7
  1257. a107 12
  1258.     /*
  1259.      * The operations are only used for synchronization.  They
  1260.      * just need to complete.
  1261.      */
  1262.     statePtr->opTable.open = NullProc;
  1263.     statePtr->opTable.close = NullProc;
  1264.     statePtr->opTable.read = NullProc;
  1265.     statePtr->opTable.write = NullProc;
  1266.     statePtr->opTable.ioctl = NullProc;
  1267.     statePtr->opTable.getAttr = NullProc;
  1268.     statePtr->opTable.setAttr = NullProc;
  1269.     statePtr->opTable.select = NullProc;
  1270. d112 2
  1271. a113 2
  1272.     status = Fs_Open(devBench, FS_READ|FS_MASTER,
  1273.              0666, &statePtr->devBenchStream);
  1274. d115 2
  1275. a116 2
  1276.     status = Fs_Open(devBench, FS_CREATE|FS_READ|FS_MASTER,
  1277.              0666, &statePtr->devBenchStream);
  1278. d130 1
  1279. a130 1
  1280.     status = Fs_Read(statePtr->devBenchStream, len, (Address)¬ify,
  1281. d140 3
  1282. a142 20
  1283.     switch (notify.operation) {
  1284.         case FS_PDEV_OPEN: {
  1285.         register int streamID;
  1286.  
  1287.         streamID = notify.param.open.streamID;
  1288.         if (streamID > statePtr->maxStreamID) {
  1289.             statePtr->maxStreamID = streamID;
  1290.         }
  1291.         statePtr->clientStream[client] = streamID;
  1292.         statePtr->clientState[client] = CLIENT_OPENED;
  1293.         Io_PrintStream(io_StdErr, "Got client on stream %d\n",streamID);
  1294.         Io_Flush(io_StdErr);
  1295.         }
  1296.         break;
  1297.  
  1298.         default:
  1299.         Io_PrintStream("Unexpected control message 0x%x\n",
  1300.                 notify.operation);
  1301.         Io_Flush(io_StdErr);
  1302.         Proc_Exit(1);
  1303. d144 4
  1304. d150 8
  1305. a172 61
  1306.  * ServerStart --
  1307.  *
  1308.  *    Start the clients running.
  1309.  *    (Synchronization Style 1) The clients are synchronized by waiting
  1310.  *    for all their requests to come in, and then replying to all of them.
  1311.  *    (Synchronization Style 2) Drop into a normal select-read-reply
  1312.  *    loop as the Setup routine has done the synchronization already.
  1313.  *
  1314.  * Results:
  1315.  *    None
  1316.  *
  1317.  * Side effects:
  1318.  *    The first request-response with each client is done.
  1319.  *
  1320.  *----------------------------------------------------------------------
  1321.  */
  1322.  
  1323. void
  1324. ServerStart(data)
  1325.     ClientData data;
  1326. {
  1327.     ServerState *statePtr;
  1328.     int client;
  1329.     int amountWritten;
  1330.     ReturnStatus status;
  1331.     int *selectMask;
  1332.     int numStartedClients;
  1333.     int numReady;
  1334.  
  1335.     statePtr = (ServerState *)data;
  1336.     selectMask = (int *)Mem_Alloc(statePtr->selectMaskBytes);
  1337.     Byte_Copy(statePtr->selectMaskBytes, (Address)statePtr->selectMask,
  1338.                      (Address)selectMask);
  1339.     numStartedClients = 0;
  1340.     do {
  1341.     status = Fs_Select(statePtr->numClients, NULL, selectMask,
  1342.                 NULL, NULL, &numReady);
  1343.     for (client=0 ; client < statePtr->numClients ; client++) {
  1344.         /*
  1345.          * Look for the each client's bit in the select mask and read the
  1346.          * corresponding stream for its initial request.
  1347.          */
  1348.         if ( ! (statePtr->clientState[client] & CLIENT_STARTED) &&
  1349.         Bit_IsSet(statePtr->clientStream[client], selectMask)) {
  1350.         /*
  1351.          * Handle the client's first request.
  1352.          * Then clear the client's bit from the select mask so it
  1353.          * doesn't bother us for a bit.
  1354.          */
  1355.         ServeRequest(statePtr->clientStream[client],&statePtr->opTable);
  1356.         numStartedClients++;
  1357.         statePtr->clientState[client] |= CLIENT_STARTED;
  1358.         Bit_Clear(statePtr->clientStream[client], selectMask);
  1359.         }
  1360.     }
  1361.     } while (numStartedClients < statePtr->numClients);
  1362. }
  1363.  
  1364. /*
  1365.  *----------------------------------------------------------------------
  1366.  *
  1367. d190 2
  1368. a191 2
  1369. void
  1370. ServeRequest(clientStreamID, opTablePtr)
  1371. d193 1
  1372. a193 1
  1373.     Fs_PdevOpTable *opTablePtr;
  1374. d200 2
  1375. a201 2
  1376.     Fs_PdevRequest request;
  1377.     Fs_PdevReply reply;
  1378. d221 3
  1379. a223 4
  1380.     if ((int)request.operation <= (int)FS_PDEV_OPEN ||
  1381.         (int)request.operation >  (int)FS_PDEV_SET_ATTR) {
  1382.         Io_PrintStream("ServeRequest: bad operation 0x%x\n",
  1383.             request.operation);
  1384. d254 2
  1385. a255 42
  1386.     switch (request.operation) {
  1387.         case FS_PDEV_OPEN:
  1388.         Io_PrintStream(io_StdErr,
  1389.             "Warning, got open on request stream\n");
  1390.         break;
  1391.         case FS_PDEV_CLOSE:
  1392.         status = (*opTablePtr->close)(clientStreamID,
  1393.             request.requestSize, requestBuf,
  1394.             request.replySize, replyBuf);
  1395.         break;
  1396.         case FS_PDEV_READ:
  1397.         status = (*opTablePtr->read)(clientStreamID,
  1398.             request.requestSize, requestBuf,
  1399.             request.replySize, replyBuf);
  1400.         break;
  1401.         case FS_PDEV_WRITE:
  1402.         status = (*opTablePtr->write)(clientStreamID,
  1403.             request.requestSize, requestBuf,
  1404.             request.replySize, replyBuf);
  1405.         break;
  1406.         case FS_PDEV_IOCTL:
  1407.         status = (*opTablePtr->ioctl)(clientStreamID,
  1408.             request.requestSize, requestBuf,
  1409.             request.replySize, replyBuf);
  1410.         break;
  1411.         case FS_PDEV_SELECT:
  1412.         status = (*opTablePtr->select)(clientStreamID,
  1413.             request.requestSize, requestBuf,
  1414.             request.replySize, replyBuf);
  1415.         break;
  1416.         case FS_PDEV_GET_ATTR:
  1417.         status = (*opTablePtr->getAttr)(clientStreamID,
  1418.             request.requestSize, requestBuf,
  1419.             request.replySize, replyBuf);
  1420.         break;
  1421.         case FS_PDEV_SET_ATTR:
  1422.         status = (*opTablePtr->setAttr)(clientStreamID,
  1423.             request.requestSize, requestBuf,
  1424.             request.replySize, replyBuf);
  1425.         break;
  1426.     }
  1427.  
  1428. d261 1
  1429. d279 1
  1430. a279 1
  1431.     return;
  1432. d292 1
  1433. d298 1
  1434. a298 1
  1435.  * ServerWait --
  1436. d300 2
  1437. a301 3
  1438.  *    Wait for the client's to complete.  They signal this by simply
  1439.  *    writing to their stream.  All we need to do is wait for a request
  1440.  *    from each client.
  1441. d307 1
  1442. a307 1
  1443.  *    The first request-response with each client is done.
  1444. d313 1
  1445. a313 1
  1446. ServerWait(data)
  1447. a324 2
  1448.     Byte_Copy(statePtr->selectMaskBytes, (Address)statePtr->selectMask,
  1449.                      (Address)selectMask);
  1450. d327 2
  1451. d336 1
  1452. a336 2
  1453.         if ( ! (statePtr->clientState[client] & CLIENT_FINISHED) &&
  1454.         Bit_IsSet(statePtr->clientStream[client], selectMask)) {
  1455. d338 3
  1456. a340 3
  1457.          * Handle the client's last request.
  1458.          * Then clear the client's bit from the select mask so it
  1459.          * doesn't bother us for a bit.
  1460. d342 9
  1461. a350 5
  1462.         ServeRequest(statePtr->clientStream[client],
  1463.                  &statePtr->opTable);
  1464.         numFinishedClients++;
  1465.         statePtr->clientState[client] |= CLIENT_FINISHED;
  1466.         Bit_Clear(statePtr->clientStream[client], selectMask);
  1467. d354 2
  1468. d375 1
  1469. a375 1
  1470. NullProc(streamID, requestSize, requestBuf, replySize, replyBuf)
  1471. d377 1
  1472. a377 1
  1473.     int requestSize;
  1474. a378 1
  1475.     int replySize;
  1476. d381 2
  1477. a382 2
  1478.     if (replySize > 0) {
  1479.     Byte_Zero(replySize, replyBuf);
  1480. d384 180
  1481. @
  1482.  
  1483.  
  1484. 1.3
  1485. log
  1486. @added Op table
  1487. @
  1488. text
  1489. @d13 1
  1490. a13 1
  1491. static char rcsid[] = "$Header: server.c,v 1.2 87/05/01 15:49:52 brent Exp $ SPRITE (Berkeley)";
  1492. d22 1
  1493. a54 11
  1494. /*
  1495.  * FS_SET_SELECT_BIT(selectMask, streamID)
  1496.  *    int *selectMask;
  1497.  *    int streamID;
  1498.  *
  1499.  *    This is a macro that sets a bit in an array of integers that is
  1500.  *    to be used as a mask for the Fs_Select system call.
  1501.  */
  1502. #define BITS_PER_INT    (sizeof(int) * 8)
  1503. #define FS_SET_SELECT_BIT(selectMask, streamID) \
  1504.     selectMask[ streamID / BITS_PER_INT ] |= (1 << (streamID % BITS_PER_INT))
  1505. a56 23
  1506.  * FS_IS_SELECT_BIT_SET(selectMask, streamID)
  1507.  *    int *selectMask;
  1508.  *    int streamID;
  1509.  *
  1510.  *    This is a macro that tests a bit in an array of integers to see
  1511.  *    if it is set.
  1512.  */
  1513.  
  1514. #define FS_IS_SELECT_BIT_SET(selectMask, streamID) \
  1515.     (selectMask[ streamID / BITS_PER_INT ] & (1 << (streamID % BITS_PER_INT)))
  1516.  
  1517. /*
  1518.  * FS_CLEAR_SELECT_BIT(selectMask, streamID)
  1519.  *    int *selectMask;
  1520.  *    int streamID;
  1521.  *
  1522.  *    This is a macro that clears a bit in an array of integers.
  1523.  */
  1524.  
  1525. #define FS_CLEAR_SELECT_BIT(selectMask, streamID) \
  1526.     selectMask[ streamID / BITS_PER_INT ] &= ~(1 << (streamID % BITS_PER_INT))
  1527.  
  1528. /*
  1529. d95 1
  1530. a95 1
  1531.     Fs_PdevNotification notify;
  1532. d136 1
  1533. a136 1
  1534.     len = sizeof(Fs_PdevNotification);
  1535. a140 1
  1536.         Io_Flush(io_StdErr);
  1537. d142 1
  1538. a142 1
  1539.     } else if (amountRead != sizeof(Fs_PdevNotification)) {
  1540. d151 1
  1541. a151 1
  1542.         streamID = notify.data;
  1543. d157 1
  1544. a157 2
  1545.         Io_PrintStream(io_StdErr, "Got client on stream %d\n",
  1546.                 streamID);
  1547. a158 1
  1548.         break;
  1549. d160 2
  1550. d164 1
  1551. a164 1
  1552.             notify.operation);
  1553. d173 1
  1554. a173 2
  1555.     statePtr->selectMaskBytes = (statePtr->maxStreamID / BITS_PER_INT + 1) *
  1556.                         sizeof(int);
  1557. d177 1
  1558. a177 2
  1559.     FS_SET_SELECT_BIT(statePtr->selectMask,
  1560.               statePtr->clientStream[client]);
  1561. d228 1
  1562. a228 2
  1563.         FS_IS_SELECT_BIT_SET(selectMask,
  1564.                      statePtr->clientStream[client])) {
  1565. d234 1
  1566. a234 2
  1567.         ServeRequest(statePtr->clientStream[client],
  1568.                  &statePtr->opTable);
  1569. d237 1
  1570. a237 1
  1571.         FS_CLEAR_SELECT_BIT(selectMask, statePtr->clientStream[client]);
  1572. d283 2
  1573. a284 3
  1574.     len = sizeof(Fs_PdevRequest);
  1575.     status = Fs_Read(clientStreamID, len, (Address)&request,
  1576.         &amountRead);
  1577. a286 1
  1578.     Io_Flush(io_StdErr);
  1579. d288 1
  1580. a288 1
  1581.     } else if (amountRead != sizeof(Fs_PdevRequest)) {
  1582. d318 1
  1583. d324 1
  1584. d369 1
  1585. d375 1
  1586. a375 1
  1587.     status = Fs_Write(clientStreamID, sizeof(Fs_PdevReply), (Address)&reply,
  1588. d403 1
  1589. a403 1
  1590.     (void)Fs_Write(clientStreamID, sizeof(Fs_PdevReply), (Address)&reply,
  1591. d450 1
  1592. a450 2
  1593.         FS_IS_SELECT_BIT_SET(selectMask,
  1594.                      statePtr->clientStream[client])) {
  1595. d460 1
  1596. a460 1
  1597.         FS_CLEAR_SELECT_BIT(selectMask, statePtr->clientStream[client]);
  1598. @
  1599.  
  1600.  
  1601. 1.2
  1602. log
  1603. @*** empty log message ***
  1604. @
  1605. text
  1606. @d13 1
  1607. a13 1
  1608. static char rcsid[] = "$Header: server.c,v 1.1 87/02/17 15:10:15 brent Exp $ SPRITE (Berkeley)";
  1609. d28 10
  1610. d147 1
  1611. @
  1612.  
  1613.  
  1614. 1.1
  1615. log
  1616. @Initial revision
  1617. @
  1618. text
  1619. @d28 1
  1620. d33 1
  1621. d78 7
  1622. d109 1
  1623. a109 1
  1624. ServerSetup(numClients, dataPtr, opTablePtr)
  1625. a111 1
  1626.     Fs_PdevOpTable *opTablePtr;
  1627. d115 1
  1628. d126 11
  1629. a136 1
  1630.     statePtr->opTable = *opTablePtr;
  1631. d167 2
  1632. a168 1
  1633.         "Warning, short read on control stream\n");
  1634. d180 3
  1635. d184 1
  1636. d237 1
  1637. d317 1
  1638. a317 1
  1639.     } else if (amountRead != sizeof(Fs_PdevRequest) {
  1640. d460 1
  1641. d491 30
  1642. @
  1643.